package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.FollowAuctionResponse
import com.gexiaobao.pigeon.databinding.ItemFollowSubjectBinding

/**
 * @Author      : hxw
 * @Date        : 2024/11/30 16:38
 * @Describe    :
 */
class AdapterFollowSubject(data: ArrayList<FollowAuctionResponse>) :
    BaseQuickAdapter<FollowAuctionResponse, DataBindBaseViewHolder>(R.layout.item_follow_subject, data) {
    @SuppressLint("NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: FollowAuctionResponse) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemFollowSubjectBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val orgType = when (item.orgType) {
            2 -> "协会"
            1 -> "俱乐部"
            else -> "公棚"
        }
        holder.setText(R.id.tvItemOrgType, orgType)
        holder.setText(R.id.tvItemSpecialOrgNameCount, item.orgName + "   " + data.size + "羽")

        holder.itemView.apply {
            binding.recyclerView.adapter = null
            if (item.items.isEmpty()) {
                holder.setGone(R.id.recyclerView, true)
                return
            }
            holder.setGone(R.id.recyclerView, false)
            val mAdapter = AdapterFollowAuctionPigeons(arrayListOf())
            binding.recyclerView.apply {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                adapter = mAdapter
                mAdapter.setList(item.items)
                mAdapter.notifyDataSetChanged()
            }

//            mAdapter.setOnItemClickListener { _, _, position ->
//                mOnItemClickListener?.onItemClick(holder.layoutPosition)
//            }
        }
    }
}